package com.edu.study.base.commonController;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.edu.common.county.domain.County;
import com.edu.common.county.service.ICountyService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.uuid.IdUtils;

/**
 * 区县信息Controller
 * 
 * @author ruoyi
 * @date 2021-02-18
 */
@RestController
@RequestMapping("/county")
public class CountyController extends BaseController
{
    @Autowired
    private ICountyService countyService;

    /**
     * 查询区县信息列表
     */
    @PreAuthorize("@ss.hasPermi('systemsetup:county:list')")
    @GetMapping("/list")
    public TableDataInfo list(County county)
    {
        startPage();
        List<County> list = countyService.selectCountyList(county);
        return getDataTable(list);
    }

    /**
     * 导出区县信息列表
     */
    @PreAuthorize("@ss.hasPermi('systemsetup:county:export')")
    @Log(title = "区县信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(County county)
    {
        List<County> list = countyService.selectCountyList(county);
        ExcelUtil<County> util = new ExcelUtil<County>(County.class);
        return util.exportExcel(list, "county");
    }

    /**
     * 获取区县信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('systemsetup:county:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(countyService.selectCountyById(id));
    }

    /**
     * 新增区县信息
     */
    @PreAuthorize("@ss.hasPermi('systemsetup:county:add')")
    @Log(title = "区县信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody County county)
    {
        county.setCountyCode(IdUtils.simpleUUID());
        return toAjax(countyService.insertCounty(county));
    }

    /**
     * 修改区县信息
     */
    @PreAuthorize("@ss.hasPermi('systemsetup:county:edit')")
    @Log(title = "区县信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody County county)
    {
        return toAjax(countyService.updateCounty(county));
    }

    /**
     * 删除区县信息
     */
    @PreAuthorize("@ss.hasPermi('systemsetup:county:remove')")
    @Log(title = "区县信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(countyService.deleteCountyByIds(ids));
    }
}
